# -*- coding:utf-8 -*-

products = [['iphone', 6888], ['MacPro', 14800], ['小米6', 2499], ['Coffee', 31], ['Book', 60], ['Nike', 699]]
#  print("\033[0;31mWelcome To The Shopping\033[0m".center(38))
print('''
1、请选择对应的商品名称
2、输入q退出购买
''')
# 打印商品
shop = dict(products)
print('-' * 10 + '商品列表' + '-' * 10)
print('商品', '\t', '单价')
shop_cars = {}
for k, v in shop.items():
    print(k, '\t', v)
print('-' * 26)


# 选择购买商品
def go_shop():
    while True:
        goods = input('请输入你要购买的商品：').strip()
        if goods == 'q':
            shop_car()
            break
        if goods not in shop.keys():
            print('没有该商品，请重新选择：')
            continue
        else:
            if goods in shop_cars:
                shop_cars[goods] = shop_cars[goods] + 1
            else:
                shop_cars[goods] = 1


# 打印购物车以及商品总价
def shop_car():
    cost=0
    print('\033[0;31m您购买的商品清单\033[0m'.center(35,'-'))
    for k, v in shop_cars.items():
        print('商品：{}\t个数：{}\t花费：{}'.format(k, v, shop[k] * v))
        cost += shop[k] * v
    print('')
    print('总共花费：{}'.format(cost))
    print('-'*29)


go_shop()
# 缺失个购买成功的提示

